﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Spanner
{
    public abstract class TemplateModel : Model
    {
        internal string TemplateID { get { return Name + "__template__"; } }

        internal const string TemplateIDVarName = "__templateID";

        internal Var<string> TemplateIDVar;
    }

    public class TemplateModel<T> : TemplateModel {

        internal TemplateModel() { } // Keep C# happy with a nullary constructor.

        public TemplateModel(
            string name,
            Html html,
            Func<Param<T>, Act> initAct,
            params Model[] modelDependencies
        )
        {
            Name = name;
            Html = html;
            ModelDependencies = modelDependencies;
            var param = new Param<T> { };
            InitParam = param;
            InitAct = initAct(param);
            IsLibraryModel = false;
            IsTemplateModel = true;
            TemplateIDVar = UI.Var<string>(TemplateIDVarName, TemplateID);
        }
    }
}
